const path = require('path')
const webpack = require('webpack')
const htmlPlugin = require('html-webpack-plugin');

module.exports = {
  entry: [
      'webpack-dev-server/client?http://0.0.0.0:8300',
      'webpack/hot/only-dev-server',
      path.resolve(__dirname, 'src/index.js')
  ],
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js'
  },
  devtool: 'source-map',
  devServer: {
      //contentBase: "./build",//本地服务器所加载的页面所在的目录
      historyApiFallback: true,//不跳转
      inline: true,//实时刷新
      hot:true
  } ,
  module: {
      rules: [
          {
              test: /\.(js|jsx)$/,
              loader: 'babel-loader',
              include: /src/,
              enforce: "pre",
          },
          {
              test: /\.css$/,
              loader: 'style-loader!css-loader'
          },
          {
              test: /\.less$/,
              loader: 'style-loader!css-loader!less-loader'
          },
          {
              test: /\.scss$/,
              loader: 'style-loader!css-loader!sass-loader'
          },
          {
              test: /\.(ttf|eot|svg|woff|woff2|png|jpg|gif)(\?.+)?$/,
              use: {
                  loader: 'url-loader',
                  query: {
                      name: '[hash:12].[ext]',
                      limit: 10000
                  }
              }
          }
      ]
  },
  plugins: [
      new htmlPlugin({
          title: 'Hot Module Replacement',
          template: './public/index.html',
      }),
      new webpack.HotModuleReplacementPlugin()
  ]
}